package com.santoker.user.service.controller.file;

import com.santoker.baseservice.ApiResponseBody;
import com.santoker.user.service.controller.BaseController;
import com.santoker.user.service.dto.vo.file.FileInfoVo;
import com.santoker.user.service.service.biz.file.FileUploadService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import static org.springframework.web.bind.annotation.RequestMethod.POST;

@Api(tags = "文件上传相关api")
@RestController
@RequestMapping(value = {"/lian/manager/file"})
public class FileUploadController extends BaseController {

    @Autowired
    private FileUploadService fileService;

    @ApiOperation(value = "上传文件api", notes = "通过multipart/form-data的方式上传，返回文件")
    @ApiImplicitParams({
    })
    @RequestMapping(value = {"/upload"}, method = {POST})
    @ResponseStatus(HttpStatus.OK)
    @ResponseBody
    public ApiResponseBody upload(
            @ApiParam(required = true, value = "文件")
            @RequestParam(value = "file", required = true) MultipartFile file
    ) {
        FileInfoVo imgInfoVo = fileService.upload(file, "lian");
        return ApiResponseBody.createSuccessBody(imgInfoVo);
    }

}
